package com.engine4cloud.tdf.supervision.controller.inner;

import com.engine4cloud.tdf.common.core.constant.enums.ChangePlaceTypeEnum;
import com.engine4cloud.tdf.common.core.util.R;
import com.engine4cloud.tdf.common.data.web.response.PageInfo;
import com.engine4cloud.tdf.common.log.annotation.SysLog;
import com.engine4cloud.tdf.common.security.annotation.Inner;
import com.engine4cloud.tdf.supervision.dto.create.SpChangePlaceCreateDTO;
import com.engine4cloud.tdf.supervision.dto.query.SpChangePlaceQueryDTO;
import com.engine4cloud.tdf.supervision.dto.result.EnumsTypeResultDTO;
import com.engine4cloud.tdf.supervision.dto.result.SpChangePlaceResult;
import com.engine4cloud.tdf.supervision.dto.update.SpChangePlaceUpdateDTO;
import com.engine4cloud.tdf.supervision.service.SpChangePlaceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 审批-执行地变更管理-inner
 *
 * @author wenjie
 * @date 2024-04-10 11:04:52
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/inner/change/place")
@Tag(description = "ChangePlaceWeb", name = "审批-执行地变更管理-inner")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class SpChangePlaceInnerController {

    private final SpChangePlaceService spChangePlaceService;

    /**
     * 执行地变更类型
     */
    @Inner
    @Operation(summary = "执行地变更类型", description = "执行地变更类型")
    @GetMapping("/category")
    public R<List<EnumsTypeResultDTO>> category() {
        List<EnumsTypeResultDTO> labelList = Arrays.stream(ChangePlaceTypeEnum.values())
                .map(state -> new EnumsTypeResultDTO(state.getType(), state.getDesc()))
                .collect(Collectors.toList());
        return R.ok(labelList);
    }

    /**
     * 分页查询
     *
     * @param dto 执行地变更信息
     * @return R<PageInfo < SpChangePlaceResult>>
     */
    @Inner
    @Operation(summary = "分页查询", description = "分页查询")
    @PostMapping("/page")
    public R<PageInfo<SpChangePlaceResult>> pageList(@Valid @RequestBody SpChangePlaceQueryDTO dto) {
        return R.ok(spChangePlaceService.pageList(dto));
    }

    /**
     * 通过id查询执行地变更信息
     *
     * @param id id
     * @return R
     */
    @Inner
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}")
    public R<SpChangePlaceResult> getById(@PathVariable("id") Long id) {
        return R.ok(spChangePlaceService.getById(id));
    }

    /**
     * 新增执行地变更信息
     *
     * @param dto 执行地变更信息
     * @return R
     */
    @Inner
    @Operation(summary = "新增执行地变更信息", description = "新增执行地变更信息")
    @SysLog("新增执行地变更信息")
    @PostMapping
    public R<Boolean> apply(@Valid @RequestBody SpChangePlaceCreateDTO dto) {
        return R.ok(spChangePlaceService.create(dto));
    }

    /**
     * 修改执行地变更信息
     *
     * @param dto 执行地变更信息
     * @return R
     */
    @Inner
    @Operation(summary = "修改执行地变更信息", description = "修改执行地变更信息")
    @SysLog("修改执行地变更信息")
    @PutMapping
    public R<Boolean> update(@Valid @RequestBody SpChangePlaceUpdateDTO dto) {
        return R.ok(spChangePlaceService.update(dto));
    }

}